import re
import ConfigParser

acl_conf = "servers.conf"

class pyPopeye_access(object):
    def __init__(self):
        self.acl = {}
    
    def __setitem__(self, acct, hostmask):
        self.acl[acct] = re.compile(hostmask)
    
    def __getitem__(self, hostmask):
        for i, mask in self.acl.values():
            if i.match(hostmask):
                return mask
        return False
    
    def __delitem__(self, acct):
        global cfg, sect, acl_config
        
        del self.acl[acct]
        cfg.remove_option(sect, acct)
        cfg.write(acl_conf)
    
    def __str__(self):
        return str(self.acl)

acl = pyPopeye_access()

cfg = ConfigParser.ConfigParser()
cfg.read(acl_conf)
sect = 'access'
for k,v in cfg.items(sect):
    acl[k] = v
